package com.idea.cery.springboot1.service.impl;

import com.idea.cery.springboot1.bean.User;
import com.idea.cery.springboot1.dao.JdbcDao;
import com.idea.cery.springboot1.service.JdbcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class JdbcServiceImpl implements JdbcService {
    @Autowired
    private JdbcDao jdbcDao;


    @Override
    public String update(User user) {
        int re = jdbcDao.update(user);
        String str = "更新失败";
        if (re > 0) {
            str = "更新成功";
        }
        return str;
    }

    @Override
    public String deleteById(String id) {
        int re = jdbcDao.deleteById(id);
        String str = "删除失败";
        if (re > 0) {
            str = "删除成功";
        }
        return str;
    }

    @Override
    public String insertUser(User user) {
        int re = jdbcDao.insert(user);
        String str = "添加失败";
        if (re > 0) {
            str = "添加成功";
        }
        return str;
    }

    @Override
    public List<Map<String, Object>> findAllUser() {
        List<Map<String, Object>> ml = jdbcDao.listAll();
        return ml;
    }
}
